package com.udaye.movie.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import java.util.List;

/**
 * Created by lxy on 2016/8/24 16:47.
 */
public class FragmentAdapter extends FragmentPagerAdapter {

    private List<Fragment> fragments;
    private List<?> titles;
    public FragmentAdapter(FragmentManager fm, List<Fragment> fragments) {
        this(fm,fragments,null);
    }

    public <T> FragmentAdapter(FragmentManager fm, List<Fragment> fragments, List<T> titles) {
        super(fm);
        this.fragments = fragments;
        this.titles = titles;
    }

    @Override
    public Fragment getItem(int position) {
        return fragments.get(position);
    }

    @Override
    public int getCount() {
        return fragments != null ? fragments.size() : 0;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return titles !=null?titles.get(position).toString():"";
    }
}
